package com.egg.ylt.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.egg.ylt.R;
import com.egg.ylt.activity.ACT_WaterBathDivision;
import com.egg.ylt.pojo.NatatoriumByidEntity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by sichaoqi on 2018/9/4.
 */

public class ADA_TeacherList extends RecyclerView.Adapter<ADA_TeacherList.TeacherViewHolder> {

    private Context mContext;
    private LayoutInflater mInflater;
    private List<NatatoriumByidEntity.TeacherListBean> mList;
    private OnItemClickListener mItemListener;

    public ADA_TeacherList(Context mContext) {
        this.mContext = mContext;
        mInflater = LayoutInflater.from(mContext);
        mList = new ArrayList<>();
    }

    public void setTeacherList(List<NatatoriumByidEntity.TeacherListBean> list){
        if (mList != null){
            mList.clear();
        }
        mList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public TeacherViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new TeacherViewHolder(mInflater.inflate(R.layout.item_shop_details_water_teacher, parent, false));
    }

    @Override
    public void onBindViewHolder(TeacherViewHolder holder, int position) {
        final NatatoriumByidEntity.TeacherListBean teacherListBean = mList.get(position);

        Glide.with(mContext)
                .load(teacherListBean.getIamgeUrl())
                .placeholder(R.mipmap.ic_teacher_default)
                .into(holder.itemShopWaterIvImg);
        holder.itemShopWaterTvName.setText(teacherListBean.getName());
        holder.itemShopWaterTvAge.setText(teacherListBean.getExperience());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, ACT_WaterBathDivision.class);
                intent.putExtra("id", teacherListBean.getId());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class TeacherViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.item_shop_water_iv_img)
        ImageView itemShopWaterIvImg;
        @BindView(R.id.item_shop_water_tv_name)
        TextView itemShopWaterTvName;
        @BindView(R.id.item_shop_water_tv_age)
        TextView itemShopWaterTvAge;
        public TeacherViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    public interface OnItemClickListener{
        void onItemClick(String id);
    }

    public void setOnItemClickListener(OnItemClickListener listener){
        this.mItemListener = listener;
    }
}
